****************************************************************************
*
*      Programa que apaga o registro do arquivo pedido
*               anterior a um determinado data
*
*      Autor: Eng. Luis Lin
*
*      Date : 19.01.04
*
****************************************************************************
#include "Inkey.ch"
#Include "box.ch"
local ddata := date() - 365
priv ncount
REQUEST DBFCDX
RddSetDefault('dbfcdx')
set date british


close databases
set deleted off
do daclib
cls

  if  Disp_sn({"Este programa apaga todos pedidos  ante-",;
               "rior a data que voce vai digitar........",;
               "voce quer continuar?                    "},.t.)

      @ 4, 20 get ddata  when mess_get("Digite a data a ser apagado a este data")
      read

  endif

  use clientes index ncodc new alias CFO
  use pedidoma index npedido new alias PEDM

  sele PEDM
  go top

  do while PEDM->pm_ddatped < ddata
           if ! deleted()
                 delete
                 deleitem(PEDM->pm_npedido,1)
           endif
           skip
  enddo

*  sele PEDM
*  pack

  close PEDM
  close CFO

close databases
cls
return .t.


/*
     elseif p == "R"
               if lastkey() <> 27
                  set deleted off
                  if deleted()
                     if Disp_sn({"Chamar de Volta este Pedido ? <S/N> "})
                        recall
                        deleitem(ws_npedido,2)
                        descitem(1)     // 1- subtrair qty do item
                     endif
*                     set deleted on
                   else
                       Disp_mens({"Pedido nao Cancelado,Aperte qquer Tecla!"},.t.)
                   endif
                endif
               set deleted on
               close PEDM
               close CFO
               return .t.

*/


static function deleitem(npedi,n1)
local nWorkArea := select() , cod:= PEDM->cl_ncodcli
    use pedidosi index npedit,ncodit new alias PEDI
*   set order to 1
    set order to tag npeditem
    set softseek on
    seek str(npedi,5,0)
	set softseek off
    sele PEDM
    if n1 = 1
*      PEDM->pm_cnomcfo := "Cancelado"
    else
*      PEDM->pm_cnomcfo := clie(@cod)
    endif
    sele PEDI
    set order to tag npeditem
    do while PEDI->pi_npedido == npedi
       if n1 = 1
          delete
          skip
       else
          recall
          skip
       endif
    enddo
    close PEDI
    select(nWorkArea)
return .t.



Function DispBar()
LOCAL nCount := 0
Public nRec
@ 19,18,21,61 BOX B_DOUBLE
@ 20,19 clear to 20,60
@ 20,20 say chr(219)
nCount := 0
nRec := Reccount() / 40
return nCount

Function dacCount(xStr, nCount)
*Public nRec
IF  nCount == NIL
    RETURN xStr
END
nCount ++
if nCount > nRec
   @ 20, col() say chr(219)
   nCount := 0
endif
RETURN xStr


